import xlrd
import xlwt
from xlrd import xldate_as_tuple
import datetime

import sys
import os
import struct
# import string

DEFAULT_PCM_DIR = "./default_tones/"

UART_FILE = "./uartCmd.json"
WEB_FILE = "./指令词文本.txt"
PARM_FILE = "./src/yfc_parm.h"

WEB_LEARN_FILE = "./学习词文本.txt"
LEARN_E_CMD_PATH = "./eCmd.txt"
LEARN_SOUND_PATH = "./eSound.txt"

'''
xlrd中单元格的数据类型
数字一律按浮点型输出，日期输出成一串小数，布尔型输出0或1，所以我们必须在程序中做判断处理转换
成我们想要的数据类型
0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error


'''

class ExcelData():

	def __init__(self, data_path, sheetname):
		#定义一个属性接收文件路径
		self.data_path = data_path
		# 定义一个属性接收工作表名称
		self.sheetname = sheetname
		# 使用xlrd模块打开excel表读取数据
		self.data = xlrd.open_workbook(self.data_path)
		# 根据工作表的名称获取工作表中的内容（方式①）
		self.table = self.data.sheet_by_name(self.sheetname)
		# 根据工作表的索引获取工作表的内容（方式②）
		# self.table = self.data.sheet_by_name(0)
		# 获取第一行所有内容,如果括号中1就是第二行，这点跟列表索引类似
		self.keys = self.table.row_values(4)
		#print(self.keys)
		# 获取工作表的有效行数
		self.rowNum = self.table.nrows
		# 获取工作表的有效列数
		self.colNum = self.table.ncols

		self.write_data = xlwt.Workbook()
		self.write_sheet = self.write_data.add_sheet("cmd")
		#self.write_sheet.write(0,0,"test")
		#self.write_data.save('yfc_simple_cmd.xls')

	def creatUartHead(self, uartFile):
		uartFile.write("/*************************************** \n")
		uartFile.write("易峰晨云知声模块通用串口协议 \n")
		uartFile.write("{ \n")
		uartFile.write("	{{指令内容},{通讯数据}}, \n")
		uartFile.write("}\n")
		uartFile.write("|   byte0   |	   byte1	|   byte2	 |  byte3	|   byte4		|   byte5			|   byte6				|   byte7   |\n")
		uartFile.write("|   头	   |	   序号	|   cmd1	 |   cmd2	|   play（0,1）	|   addr（0，1,2,3）	|   chectSum（0-5byte）	|   尾	   |\n")
		uartFile.write("PS: 从机发送序号为零的时候为主动播报\n")
		uartFile.write("***************************************/ \n")

	def creatWebHead(self, webFile):
		webFile.write("/*************************************** \n")
		webFile.write("易峰晨云知声模块通用协议指令词文本 \n")
		webFile.write("***************************************/ \n")
		webFile.write("把一下内容复制到云知声官网的语音指令处 \n")
		webFile.write(" \n")
		webFile.write(" \n")
		webFile.write(" \n")

	def getUartData(self, i):
		sstr = ''
		for j in range(11, self.colNum):
			c_type = self.table.cell(i, j).ctype
			c_cell = self.table.cell_value(i, j)

			if c_type == 2 and c_cell % 1 == 0:  # 如果是整形
				c_cell = int(c_cell)
			if j == 11:
				sstr += '0x' + str(c_cell)
			elif j > 11 and j < 19:
				sstr += ', 0x' + str(c_cell)
		sstr += "\", \"" + "work" + "\": \"" + self.table.cell_value(i, 1) + " \" " + ", " + "\"cmd\"" + ":" + "\""

		return sstr

	def writeExcelLine(self):
		self.write_sheet.write(0, 0, "需求")
		self.write_sheet.write(0, 1, "指令内容")
		self.write_sheet.write(0, 2, "备注")
		self.write_sheet.write(0, 3, "序号")
		self.write_sheet.write(0, 4, "语音指令1")
		self.write_sheet.write(0, 5, "语音指令2")
		self.write_sheet.write(0, 6, "语音指令3")
		self.write_sheet.write(0, 7, "回复语1")
		self.write_sheet.write(0, 8, "回复语2")
		self.write_sheet.write(0, 9, "回复语3")
		self.write_sheet.write(0, 10, "")
		self.write_sheet.write(0, 11, "头")
		self.write_sheet.write(0, 12, "标识（自加）")
		self.write_sheet.write(0, 13, "cmd1")
		self.write_sheet.write(0, 14, "cmd2")
		self.write_sheet.write(0, 15, "play（0,1）")
		self.write_sheet.write(0, 16, "addr（0，1,2,3）")
		self.write_sheet.write(0, 17, "chectSum（0-5byte）")
		self.write_sheet.write(0, 18, "尾")
		self.write_sheet.write(0, 19, "学习提示音")
		self.write_sheet.write(0, 20, "学习标注")

	def creatUartWeb(self,webFile,uartFile):
		#写入头行标识
		self.writeExcelLine()
		writeCol = 1

		cmdNum = 1
		flagStart = 0
		uartFile.write("[")
		for i in range(2, self.rowNum):
			c_type = self.table.cell(i, 0).ctype
			c_cell = self.table.cell_value(i, 0)
			if c_type == 0 and c_cell != '*':
				continue
			c_type = self.table.cell(i, 3).ctype #获取序号
			serial = self.table.cell_value(i, 3)

			# #写入学习数据-------------------------------
			# learn_type = self.table.cell(i, 20).ctype
			# learn_value = self.table.cell_value(i, 20)
			# if c_type != 0 and learn_value == '*':
			# 	self.crearLearnWorkList( i, )
			# #-----------------------------------------

			#复制带*号的一行到新的协议文件
			if serial >= 1000 and serial < 1100:
				print("compete")
			else:
				for getSerial in range(4, 21):
					getData = self.table.cell_value(i, getSerial)
					self.write_sheet.write(writeCol, getSerial, getData)
				writeCol += 1

			if c_type == 2 and serial % 1 == 0:  # 如果是整形
				serial = int(serial)
			strUart = ",\n	{   \"uartData\" : \" "
			if serial == 3:
				sstr = 'volumeUpUni'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')

			elif serial == 4:
				sstr = 'volumeDownUni'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')

			elif serial == 5:
				sstr = 'volumeMaxUni'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')

			elif serial == 6:
				sstr = 'volumeMinUni'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')

			elif serial == 7:
				sstr = 'volumeMidUni'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')

			elif serial == 28:
				sstr = 'click'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				#webFile.write(sstr+ '\n')

			elif serial == 29:
				sstr = 'doubleClick'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				#webFile.write(sstr+ '\n')

			elif serial == 10:
				sstr = 'volumeSetting'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')
			elif serial == 1:
				sstr = 'muteClean'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')
			elif serial == 2:
				sstr = 'muteSet'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')
			elif serial == 600:
				sstr = 'cmdTemp'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')
			elif serial == 500:
				sstr = 'cmdTime'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr+ '\n')

			elif serial >= 30 and serial < 90:
				sstr = 'waitup' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				#webFile.write(sstr + '\n')
			elif serial >= 90 and serial < 150:
				sstr = 'system' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
			elif serial > 149 and serial < 500:
				# 写入学习数据-------------------------------
				learn_type = self.table.cell(i, 20).ctype
				learn_value = self.table.cell_value(i, 20)
				if c_type != 0 and learn_value == '*':
					# print("learn", i, cmdNum)
					self.crearLearnWorkList(i, cmdNum)
				# -----------------------------------------

				sstr = 'auto' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
			elif serial > 600 and serial < 610:
				sstr = 'setTemp' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
			elif serial > 609 and serial < 850:
				sstr = 'temp' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
			elif serial > 500 and serial < 510:
				sstr = 'setTime' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
			elif serial > 509 and serial < 600:
				sstr = 'time' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
			elif serial == 850:
				sstr = 'giveTime'
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				for j in range(3):	#指令词输入
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				sstr += '现在是'
				#sstr += '零|一|二|三|四|五|六|七|八|九|十|十一|十二|十三|十四|十五|十六|十七|十八|十九|二十|二十一|二十二|二十三|二十四|二十五|二十六|二十七|二十八|二十九|三十|三十一|三十二|三十三|三十四|三十五|三十六|三十七|三十八|三十九|四十|四十一|四十二|四十三|四十四|四十五|四十六|四十七|四十八|四十九|五十|五十一|五十二|五十三|五十四|五十五|五十六|五十七|五十八|五十九'
				webFile.write(sstr + '\n')
			elif serial >= 900 and serial < 1000:
				sstr = 'single' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				#webFile.write(sstr + '\n')
			elif serial >= 1000 and serial < 1100:
				sstr = 'compete' + str(cmdNum)
				strUart += self.getUartData(i)
				strUart += sstr
				strUart += '\"}'
				sstr += '='
				uartFile.write(strUart)
				cmdNum += 1
				for j in range(3):
					c_type = self.table.cell(i, j+4).ctype
					c_cell = self.table.cell_value(i, j+4)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				sstr += '@'
				for j in range(3):
					c_type = self.table.cell(i, j + 7).ctype
					c_cell = self.table.cell_value(i, j + 7)
					if c_type == 0:
						break
					if j == 0:
						sstr += c_cell
					else:
						sstr += '|' + c_cell
				webFile.write(sstr + '\n')
		uartFile.write("\n] \n")
		uartFile.seek(0, 0)			#修改第一行
		uartFile.write("[ ")
		self.write_data.save('yfc_simple_cmd.xls')

	#parm 修改
	def creatParm(self, fsParm):
		fsParm.write("#ifndef __YFC_PARM_H__\n")
		fsParm.write("#define __YFC_PARM_H__\n\n")
        
		c_type = self.table.cell(0, 2).ctype #唤醒主动播报
		value = self.table.cell_value(0, 2)
		if value == '是':
			fsParm.write("#define PARM_WAITTP   0\n")
		elif value == '否':
			fsParm.write("#define PARM_WAITTP   AUTO_LIST|AUTO_PLAY\n")

		c_type = self.table.cell(1, 2).ctype #退出主动播报
		value = self.table.cell_value(1, 2)
		if value == '是':
			fsParm.write("#define PARM_EXIT   0\n")
		elif value == '否':
			fsParm.write("#define PARM_EXIT   AUTO_PLAY\n")

		c_type = self.table.cell(2, 2).ctype #指令词主动播报
		value = self.table.cell_value(2, 2)
		if value == '是':
			fsParm.write("#define PARM_CUSTOM   0\n")
		elif value == '否':
			fsParm.write("#define PARM_CUSTOM   AUTO_PLAY\n")
		
		c_type = self.table.cell(3, 2).ctype #单论播报
		value = self.table.cell_value(3, 2)
		if value == '是':
			fsParm.write("#define PARM_ONCE   FUN_EN\n")
		elif value == '否':
			fsParm.write("#define PARM_ONCE   0\n")

		c_type = self.table.cell(4, 2).ctype #静音功能播报
		value = self.table.cell_value(4, 2)
		c_type1 = self.table.cell(6, 2).ctype #静音功能播报
		value1 = self.table.cell_value(6, 2)		
		if value == '是':
			if value1 == '是':
				fsParm.write("#define PARM_MUTE   0\n")
			elif value1 == '否':
				fsParm.write("#define PARM_MUTE   AUTO_PLAY\n")
		elif value == '否':
			fsParm.write("#define PARM_MUTE   FUN_EN\n")

		c_type = self.table.cell(7, 2).ctype #音量使能
		value = self.table.cell_value(7, 2)
		c_type1 = self.table.cell(5, 2).ctype #音量功能播报
		value1 = self.table.cell_value(5, 2)		        
		if value == '是':
			if value1 == '是':
				fsParm.write("#define PARM_VOLUME   0\n")
			elif value1 == '否':
				fsParm.write("#define PARM_VOLUME   AUTO_PLAY\n")   
		elif value == '否':
			fsParm.write("#define PARM_VOLUME   FUN_EN\n")

		c_type = self.table.cell(8, 2).ctype #功放使能脚
		value = self.table.cell_value(8, 2)
		if value == '高':
			fsParm.write("#define PA_EN_LV            1\n")
			fsParm.write("#define PA_DIS_LV           0\n")
		else:
			fsParm.write("#define PA_EN_LV            0\n")
			fsParm.write("#define PA_DIS_LV           1\n")

		c_type = self.table.cell(9, 2).ctype #学习唤醒词
		value = self.table.cell_value(9, 2)
		if value == '是':
			fsParm.write("#define LEARN_WAITUP            1\n")
		else:
			fsParm.write("#define LEARN_WAITUP            0\n")

		c_type = self.table.cell(10, 2).ctype #学习指令词
		value = self.table.cell_value(10, 2)
		if value == '是':
			fsParm.write("#define LEARN_CMD            1\n")
		else:
			fsParm.write("#define LEARN_CMD            0\n")


		fsParm.write("\n#endif\n")
		
	#加入学习词的功能列表
	#生成指令词列表
	def creatLearn(self, webFile):
		# 生成指令词列表
		for i in range(4,10):
			sstr = ""
			c_type = self.table.cell(i, 1).ctype
			c_cell = self.table.cell_value(i, 1)
			sstr += c_cell #填入startStudy
			sstr += "="
			for j in range(3):
				c_type = self.table.cell(i, j + 3).ctype
				c_cell = self.table.cell_value(i, j + 3)
				if c_type == 0:
					break
				if j == 0:
					sstr += c_cell
				else:
					sstr += '|' + c_cell
			sstr += '@'
			for j in range(6):
				c_type = self.table.cell(i, j + 6).ctype
				c_cell = self.table.cell_value(i, j + 6)
				if c_type == 0:
					break
				if j == 0:
					sstr += c_cell
				else:
					sstr += '|' + c_cell
			webFile.write(sstr + '\n')
		# 修改sdk的学习列表

	#加入指令词播报指令集
	def crearLearnWorkList(self, row, num):

		listFile = open(WEB_LEARN_FILE, mode="a+", encoding='utf-8')

		c_type = self.table.cell(row, 19).ctype
		value = self.table.cell_value(row, 19)
		listFile.write(value + '\n')
		listFile.close()

		#  eCMD_auto5,
		frontStr = "eCMD_auto"
		eCmdFile = open(LEARN_E_CMD_PATH, mode="a+", encoding='utf-8')

		eCmdFile.write(frontStr + str(num) + ',\n')
		eCmdFile.close()


if __name__ == "__main__":

	uartFileOpen = open(UART_FILE, mode="w", encoding='utf-8')
	webFileOpen = open(WEB_FILE, mode="w", encoding='utf-8')

	data_path = "yfc_cmd.xlsx"
	sheetname = "cmd"
	get_data = ExcelData(data_path, sheetname)	

	cleanFd = open(LEARN_E_CMD_PATH, mode="w", encoding='utf-8')#清空文件
	cleanFd.close()

	'''
	#write_path =
	write_data = xlwt.Workbook()
	write_sheet = write_data.add_sheet("cmd")
	write_sheet.write(0,0,"test")
	write_data.save('yfc_simple_cmd.xls')
	'''

	#get_data.creatUartHead(uartFileOpen)
	get_data.creatWebHead(webFileOpen)
	get_data.creatUartWeb(webFileOpen, uartFileOpen)

	#加入参数修改部分
	parmFileOpen = open(PARM_FILE, mode="w", encoding='utf-8')
	
	data_path = "yfc_cmd.xlsx"
	sheetname = "通讯要求"
	get_data = ExcelData(data_path, sheetname)
	get_data.creatParm(parmFileOpen)
	
	data_path = "yfc_cmd.xlsx"
	sheetname = "学习功能"
	get_data = ExcelData(data_path, sheetname)
	get_data.creatLearn(webFileOpen)
	
	uartFileOpen.close()
	webFileOpen.close()

